// import api from './index'
import request from '@/utils/request'
import baseapi from '@/api/base'

const userApi = {
  Login: '/auth/login',
  Logout: '/auth/logout',
  ForgePassword: '/auth/forge-password',
  Register: '/auth/register',
  twoStepCode: '/auth/2step-code',
  SendSms: '/account/sms',
  SendSmsErr: '/account/sms_err',
  // get my info
  UserInfo: '/user/info',
  UserMenu: '/user/nav'
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login (parameter) {
  const allHeader = {
    imei: baseapi.imei,
    appId: baseapi.huiwcore_app
  }
  const appId = {
    appId: baseapi.huiwcore_app
  }
  return request({
    url: baseapi.baseUrl + baseapi.huiwcore + '/account/verify/',
    method: 'post',
    headers: allHeader,
    data: Object.assign(parameter, appId)
  })
}

export function getSmsCaptcha (parameter) {
  return request({
    url: userApi.SendSms,
    method: 'post',
    data: parameter
  })
}

export function getInfo () {
  return request({
    // url: '/user/info',
    url: baseapi.baseUrl + baseapi.huiwcore + '/forvue/person/',
    method: 'get',
    headers: {
      imei: baseapi.imei,
      appId: baseapi.huiwcore_app
      // 'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function getCurrentUserNav () {
  return request({
    url: userApi.UserMenu,
    method: 'get'
  })
}

export function logout () {
  return request({
    url: userApi.Logout,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step (parameter) {
  return request({
    url: userApi.twoStepCode,
    method: 'post',
    data: parameter
  })
}

export function selectOrg (relationType) {
  const parameters = {
    relationType: relationType,
    pageSize: 100000
  }
  // console.log(parameters)
  return request({
    url: baseapi.baseUrl + baseapi.huiwcore + '/relationOrgPerson/by/personPid/',
    method: 'get',
    headers: {
      imei: baseapi.imei,
      appId: baseapi.huiwcore_app,
      authOption: '1'
      // 'Content-Type': 'application/json;charset=UTF-8'
    },
    params: parameters
  })
}

export function getUserDepartments (orgPid) {
  return request({
    // url: '/user/info',
    url: baseapi.baseUrl + baseapi.huiwcore + '/relationDeptPerson/by/personPid/',
    method: 'get',
    headers: {
      imei: baseapi.imei,
      appId: baseapi.huiwcore_app,
      org: orgPid,
      authOption: 1
      // 'Content-Type': 'application/json;charset=UTF-8'
    }
    // params: {orgPid: orgPid}
  })
}
